package com.jiazhong.mybatis.m4;

import com.jiazhong.mybatis.m4.bean.Emp;
import com.jiazhong.mybatis.m4.mapper.EmpMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.Arrays;
import java.util.List;

public class App {

    private static void a(){
        InputStream inputStream = App.class.getClassLoader().getResourceAsStream("config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
        Emp emp = new Emp();
        emp.setEname("%李%");
        List<Emp> emps = empMapper.find1(emp);
        sqlSession.close();
    }

    private static void b(){
        InputStream inputStream = App.class.getClassLoader().getResourceAsStream("config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
        Emp emp = new Emp();
        emp.setEname("%李%");
        //emp.setJob("程序员");
        List<Emp> emps = empMapper.find2(emp);
        sqlSession.close();
    }

    private static void c(){
        InputStream inputStream = App.class.getClassLoader().getResourceAsStream("config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
        Emp emp = new Emp();
        emp.setEname("%李%");
        emp.setJob("程序员");
        List<Emp> emps = empMapper.find3(emp);
        sqlSession.close();
    }

    private static void d(){
        InputStream inputStream = App.class.getClassLoader().getResourceAsStream("config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
        Emp emp = new Emp();
        emp.setEname("你好");
        emp.setJob("程序员");
        emp.setSal(893.3);
        emp.setEmpNo(99999);
        empMapper.update2(emp);
        sqlSession.close();
    }
    private static void e(){
        InputStream inputStream = App.class.getClassLoader().getResourceAsStream("config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
        empMapper.find4("1212");
        sqlSession.close();
    }
    private static void f(){
        InputStream inputStream = App.class.getClassLoader().getResourceAsStream("config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        List<String> jobs = Arrays.asList("程序员","网页设计","歌手","aaa");
        EmpMapper mapper = sqlSession.getMapper(EmpMapper.class);
        List<Emp> result = mapper.find5(jobs);
        sqlSession.close();
    }
    private static void g(){
        InputStream inputStream = App.class.getClassLoader().getResourceAsStream("config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        EmpMapper mapper = sqlSession.getMapper(EmpMapper.class);
        mapper.find6("张");
        sqlSession.close();
    }
    public static void main(String[] args) {
       g();
    }
}